package com.kyzh.core.dialog

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import androidx.recyclerview.widget.GridLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.gushenge.core.beans.LiveNav
import com.kyzh.core.R
import com.kyzh.core.databinding.DialogLiveroomManagerBinding
import com.kyzh.core.databinding.ItemVoiceroomManagerBinding
import per.goweii.layer.core.ktx.onClickToDismiss
import per.goweii.layer.core.widget.SwipeLayout
import per.goweii.layer.dialog.DialogLayer
import per.goweii.layer.dialog.ktx.backgroundDimDefault
import per.goweii.layer.dialog.ktx.gravity
import per.goweii.layer.dialog.ktx.swipeDismiss

private var dialog : DialogLayer?=null
fun Context.showLiveRoomManagerDialog(auth:Int,listener: LiveNav.()->Unit){
    dialog =   DialogLayer(this)
    dialog!!.setContentView(getView(auth,listener))
        .backgroundDimDefault()
        .gravity(Gravity.BOTTOM)
        .swipeDismiss(SwipeLayout.Direction.BOTTOM)
        .onClickToDismiss(android.R.id.text1)
        .show()
}
private fun Context.getView(auth: Int,listener:LiveNav.()->Unit) = DialogLiveroomManagerBinding.inflate(LayoutInflater.from(this)).apply {
    val navs = arrayListOf<LiveNav>(
    )
    when(auth){
        3->{
            navs.add(LiveNav(id = R.drawable.ic_item_voiceroom_manager_edit,type = 0,name = "编辑房间" ))
            navs.add(LiveNav(id = R.drawable.ic_item_voiceroom_manager_close,type = 1,name = "关闭房间" ))
            navs.add(LiveNav(id = R.drawable.ic_item_voiceroom_manager_job,type = 2,name = "职务管理" ))
        }
        2->{
            navs.add(LiveNav(id = R.drawable.ic_item_voiceroom_manager_close,type = 1,name = "退出房间" ))
        }
        1->{
            navs.add(LiveNav(id = R.drawable.ic_item_voiceroom_manager_close,type = 1,name = "退出房间" ))
        }
        0->{
            navs.add(LiveNav(id = R.drawable.ic_item_voiceroom_manager_report,type = 3,name = "举报房间" ))
            navs.add(LiveNav(id = R.drawable.ic_item_voiceroom_manager_close,type = 1,name = "退出房间" ))
        }
    }
    rvList.apply {
        layoutManager = GridLayoutManager(this@getView,4)
        adapter = object :BaseQuickAdapter<LiveNav,BaseDataBindingHolder<ItemVoiceroomManagerBinding>>(R.layout.item_voiceroom_manager,navs){
            override fun convert(
                holder: BaseDataBindingHolder<ItemVoiceroomManagerBinding>,
                item: LiveNav
            ) {
                holder.dataBinding?.apply {
                    data = item
                    ivImage.setImageResource(item.id)
                }
                holder.itemView.setOnClickListener {
                    item.listener()
                }
            }

        }
    }
}.root
